package xyj.sparrow.client.proxy;

import org.springframework.beans.factory.FactoryBean;

import javax.annotation.Resource;
import java.lang.reflect.Proxy;

public class RpcFactoryBean<T> implements FactoryBean<T> {
    private final Class<T> classes;
    @Resource
    private RpcProxy rpcProxy;

    public RpcFactoryBean(Class<T> classes) {
        this.classes = classes;
    }

    @Override
    public T getObject() {
        return (T) Proxy.newProxyInstance(classes.getClassLoader(), new Class[]{classes}, rpcProxy);
    }

    @Override
    public Class<?> getObjectType() {
        return classes;
    }
}
